import org.junit.Test;
import utils.mysqlUtil;

import java.math.BigDecimal;
import java.sql.*;

public class T1 {
    @Test
    public void Test01() throws SQLException, ClassNotFoundException {
        //调用工具
        Connection conn = mysqlUtil.getConn();
        //编写SQL
        String sql = "select * from dept";
        PreparedStatement preparedStatement = conn.prepareStatement(sql);
        ResultSet resultSet = preparedStatement.executeQuery();
        //遍历
        while (resultSet.next()) {
            int id = resultSet.getInt("deptno");
            String dName = resultSet.getString("dname");
            String loc = resultSet.getString("loc");
            //打印
            System.out.println(id + "\t" + dName + "\t" + loc);
        }
    }
    @Test
    public void Test02() throws SQLException, ClassNotFoundException {
        //调用工具
        Connection conn = mysqlUtil.getConn();
        //编写SQL
        String sql = "select * from emp";
        PreparedStatement preparedStatement = conn.prepareStatement(sql);
        ResultSet resultSet = preparedStatement.executeQuery();
        //遍历
        while (resultSet.next()) {
            int id = resultSet.getInt("empno");
            String eName = resultSet.getString("ename");
            String job = resultSet.getString("job");
            int mgr = resultSet.getInt("mgr");
            Date hiredate = resultSet.getDate("hiredate");
            BigDecimal sal = resultSet.getBigDecimal("sal");
            BigDecimal comm = resultSet.getBigDecimal("comm");
            int deptNo = resultSet.getInt("deptno");
            //打印
            System.out.println(id + "\t" + eName + "\t" + job + "\t" + mgr + "\t" + hiredate  + "\t" + sal + "\t" + comm + "\t" + deptNo);
        }
    }
    @Test
    public void Test03() throws SQLException, ClassNotFoundException {
        //调用工具
        Connection conn = mysqlUtil.getConn();
        //编写SQL
        String sql = "select * from salgrade";
        PreparedStatement preparedStatement = conn.prepareStatement(sql);
        ResultSet resultSet = preparedStatement.executeQuery();
        //遍历
        while (resultSet.next()) {
            int grade = resultSet.getInt("grade");
            int losal = resultSet.getInt("losal");
            int hisal = resultSet.getInt("hisal");
            //打印
            System.out.println(grade + "\t" + losal + "\t" + hisal);
        }
    }
}
